/*
 * Copyright (c) 2006-2021, Halo team
 *
 * SPDX-License-Identifier: GPLv3
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-11     Eywen        the first version
 */
#include "common.h"

#if (defined SOC_FAMILY_STM32)
    #if (defined SOC_SERIES_STM32F1)
        #include "stm32f1xx_hal.h"
    #else (defined SOC_SERIES_STM32F4)
        #include "stm32f4xx_hal.h"
    #endif
#elif (defined SOC_AB32VG1)
    #include "ab32vg1_hal.h"
#endif


void delay_ms(uint32_t ms)
{
#if  (defined SOC_FAMILY_STM32)
    HAL_Delay(ms);
#elif (defined SOC_AB32VG1)
    hal_udelay(ms*1000);
#endif
}

void delay_s(uint32_t s)
{
    delay_ms(s*1000);
}

void delay_us(uint32_t us)
{
#if (defined SOC_FAMILY_STM32)
    __IO uint32_t delay = us* (SystemCoreClock / 8U);
#elif (defined SOC_AB32VG1)
    volatile uint32_t delay = us* (108000000 / 8U);
#endif
    do
    {
#ifdef SOC_FAMILY_STM32
        __NOP();
#elif (defined SOC_AB32VG1)
        asm("nop");
#endif
    }
    while (delay--);
}
